package org.zjx.action.route;

import org.zjx.action.Action;
import org.zjx.action.basic.DelayAction;
import org.zjx.action.basic.ScreenshotAction;
import org.zjx.action.game.ClickAddressAction;
import org.zjx.action.game.GameAction;
import org.zjx.core.IWindow;
import org.zjx.entity.Address;

import java.awt.*;

public class RoomInterAction extends Action {
    private final Address targetAddress;
    private final Address standPosition;
    private final Address clickPosition;

    public RoomInterAction(IWindow targetWindow, Address targetAddress,Address standPosition, Address clickPosition) {
        super(targetWindow, false);
        this.targetAddress = targetAddress;
        this.standPosition = standPosition;
        this.clickPosition = clickPosition;
    }

    @Override
    protected void doExecute() throws Exception {
        while (!getAddressNow().near(targetAddress,3)){
            if (!getAddressNow().near(standPosition,3)){
                RunningAction runAction = new RunningAction(targetWindow,standPosition);
                runAction.execute();
            }else {
                ClickAddressAction clickAction = new ClickAddressAction(targetWindow,clickPosition);
                clickAction.execute();
            }
            new DelayAction(targetWindow,3000);
        }
    }

    public Address getAddressNow() {
        new ScreenshotAction(targetWindow).execute();
        new GameAction(targetWindow).execute();
        return targetWindow.getState().getGameState().getAddress();
    }


}
